#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

typedef struct
{
    char name[6];
    int age;
} people;

int main(int argc, char* argv[])
{
    int fd, i;

    people *p_map;
    char temp;
    fd = open(argv[1], O_CREAT | O_RDWR | O_TRUNC, 00777);
    lseek(fd, sizeof(people) * 5 - 1, SEEK_SET);
    write(fd, "", 1);

    p_map = (people*) mmap(NULL, sizeof(people) * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (p_map == (void*) -1)
    {
        fprintf(stderr, "mmap: %s\n", strerror(errno));
    }

    for (i = 0; i < 10; i++)
    {
        printf("name；%s age:%d\n", (*(p_map + i)).name, (*(p_map + i)).age);

    }

    munmap(p_map, sizeof(people) * 10);

    return 0;
}
